import { createRouter, createWebHashHistory } from 'vue-router';
import routers from './router';

const router = createRouter({
  history: createWebHashHistory(),
  routes: routers,
});

// 路由守卫
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('token');
  if (to.path !== '/login' && !token) {
    next('/login');
  } else {
    next();
  }
});

export default router;